﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;

public class Test01 : MonoBehaviour {

	// Use this for initialization
	void Start () {
		url = "file://" + url;

		StartCoroutine(GetData());
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public RawImage image;
	public string url;
	IEnumerator GetData()
	{
		UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url);
		yield return uwr.SendWebRequest();

		if (uwr.isNetworkError)
		{
			Debug.LogError(uwr.error);
		}
		else
		{
			Debug.Log("Download Successed.");
			image.texture = DownloadHandlerTexture.GetContent(uwr);
		}
	}

	IEnumerator GetDataWWW()
	{
		WWW www = new WWW(url);
		yield return www;

		if (null != www.error)
		{
			Debug.LogError(www.error);
		}
		else
		{
			Debug.Log("WWW Download Successed.");
			image.texture = www.texture;
		}
	}
}
